package com.ck.shardingspheremaster.controller;

import com.ck.shardingspheremaster.model.User;
import com.ck.shardingspheremaster.service.UserService;
import com.ck.shardingspheremaster.utils.SnowFlakeGenerator;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private UserService userService;
	
	@PostMapping
	public String save(@RequestBody @ApiParam User user) {
		System.out.println(user.getName());
		long id = new SnowFlakeGenerator.Factory().create(2, 5).nextId();
		userService.save(user);
		return "success";
	}
	
	@GetMapping("/{id}")
	public User get(@PathVariable Long id) {
		User user =  userService.get(id);
		System.out.println(user.getId());
		return user;
	}
	
	
	

}
